/*
 * aalsystem.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <vdr/plugin.h>

#include "Controller.h"

using namespace std;

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "Enter description for 'aalsystem' plugin";
static const char *MAINMENUENTRY  = "Aalsystem";

class cPluginAalsystem : public cPlugin {
private:
	Controller * controller;
	bool started;
public:
	cPluginAalsystem(void);
	virtual ~cPluginAalsystem();
	virtual const char *Version(void) { return VERSION; }
	virtual const char *Description(void) { return DESCRIPTION; }
	virtual const char *CommandLineHelp(void);
	virtual bool ProcessArgs(int argc, char *argv[]);
	virtual bool Initialize(void);
	virtual bool Start(void);
	virtual void Stop(void);
	virtual void Housekeeping(void);
	virtual void MainThreadHook(void);
	virtual cString Active(void);
	virtual time_t WakeupTime(void);
	virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
	virtual cOsdObject *MainMenuAction(void);
	virtual cMenuSetupPage *SetupMenu(void);
	virtual bool SetupParse(const char *Name, const char *Value);
	virtual bool Service(const char *Id, void *Data = NULL);
	virtual const char **SVDRPHelpPages(void);
	virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
};

cPluginAalsystem::cPluginAalsystem(void){
	// Initialize any member variables here.
	// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
	// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
	// this->controller = new Controller();
	this->controller = Controller::getInstance();
}

cPluginAalsystem::~cPluginAalsystem(){
	// Clean up after yourself!
	delete(this->controller);
}

const char *cPluginAalsystem::CommandLineHelp(void){
	// Return a string that describes all known command line options.
	return NULL;
}

bool cPluginAalsystem::ProcessArgs(int argc, char *argv[]){
	// Implement command line argument processing here if applicable.
	return true;
}

bool cPluginAalsystem::Initialize(void){
	return true;
}

bool cPluginAalsystem::Start(void){
	static const char * configDir = cPlugin::ConfigDirectory(Name());
	this->controller->init(configDir);
	started = true;
	return true;
}

void cPluginAalsystem::Stop(void){
	// Stop any background activities the plugin is performing.
}

void cPluginAalsystem::Housekeeping(void){
	// Perform any cleanup or other regular tasks.
}

void cPluginAalsystem::MainThreadHook(void){
	// Perform actions in the context of the main program thread.
	// WARNING: Use with great care - see PLUGINS.html!
	if(this->started)
		this->controller->executeActionsInMainThread();
}

cString cPluginAalsystem::Active(void){
	// Return a message string if shutdown should be postponed
	return NULL;
}

time_t cPluginAalsystem::WakeupTime(void){
	// Return custom wakeup time for shutdown script
	return 0;
}

cOsdObject * cPluginAalsystem::MainMenuAction(void){
	return this->controller->mainMenuAction();
}

cMenuSetupPage *cPluginAalsystem::SetupMenu(void){
	// Return a setup menu in case the plugin supports one.
	return NULL;
}

bool cPluginAalsystem::SetupParse(const char *Name, const char *Value){
	// Parse your own setup parameters and store their values.
	return false;
}

bool cPluginAalsystem::Service(const char *Id, void *Data){
	// Handle custom service requests from other plugins
	return false;
}

const char **cPluginAalsystem::SVDRPHelpPages(void){
	// Return help text for SVDRP commands this plugin implements
	return NULL;
}

cString cPluginAalsystem::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode){
	return NULL;
}

VDRPLUGINCREATOR(cPluginAalsystem); // Don't touch this!
